package com.msmall.community.bbs.action.html;

import com.msmall.community.bbs.service.ThreadManager;
public class ThreadAction extends BBSBaseAction{

	private static final long serialVersionUID = 2059398101798471223L;

	private ThreadManager threadManager;
	
	public String save(){
		if(!getIsLogin()){
			setToSession(SESSION_THREAD_KEY, thread);
			message = getText("common.authentication.anonymous");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		if(thread == null){
			setToSession(SESSION_THREAD_KEY, thread);
			message = getText("html.bbs.thread.create.content.length.short");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		int valid = threadManager.validateThreadContent(thread.getContent());
		if(valid == 2){
			setToSession(SESSION_THREAD_KEY, thread);
			message = getText("html.bbs.thread.create.content.length.short");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		if(valid == 3){
			setToSession(SESSION_THREAD_KEY, thread);
			message = getText("html.bbs.thread.create.content.length.long");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		if(valid == 4){
			setToSession(SESSION_THREAD_KEY, thread);
			message = getText("html.bbs.thread.create.content.illegal");
			setToSession(SESSION_MESSAGE_KEY, message);
			return INPUT;
		}
		thread.setNickname(getNickname());
		threadManager.saveThread(thread, bid, tid, getUserid(), userAgentType);
		removeFromSession(SESSION_MESSAGE_KEY);
		removeFromSession(SESSION_THREAD_KEY);
		return SUCCESS;
	}
	
	public void setThreadManager(ThreadManager threadManager) {
		this.threadManager = threadManager;
	}

}
